<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/2
 * Time: 0:44
 */

class Comment extends seller_Controller
{
    private static $data = array();
    public function __construct()
    {
        parent::__construct();
        $this->load->model('Comment_model','comment_model');
        $this->checkUserFlag();
        $this->checkCompany();
    }

    public function company()
    {
        $this->load->view('seller/comment/company.html');
    }
    //加载页面
    public function project()
    {
        $this->load->view('seller/comment/project.html');
    }
    //加载页面
    public function technician()
    {
        $this->load->view('seller/comment/technician.html');
    }

//    店铺评价
    public function getCompany()
    {
        $companyId=$this->checkCompany();
        $where['company.companyId'] = $companyId;
        $where['comment.typeFlag'] = 0;
        $where['comment.deleteFlag'] = 0;
        $info = $this->comment_model->getCompany($where);
        if($info){
            show200_admin($info['data'],$info['count']);
        }else{
            show400_admin();
        }
    }

    //    项目评价
    public function getProject()
    {
        $companyId=$this->checkCompany();
        $where['project.companyId'] = $companyId;
        $where['comment.typeFlag'] = 1;
        $where['comment.deleteFlag'] = 0;
        $info = $this->comment_model->getProject($where);
        if($info){
            show200_admin($info['data'],$info['count']);
        }else{
            show400_admin();
        }
    }

    //    项目评价
    public function getTechnician()
    {
        $companyId=$this->checkCompany();
        $where['technician.companyId'] = $companyId;
        $where['comment.typeFlag'] = 2;
        $where['comment.deleteFlag'] = 0;
        $info = $this->comment_model->getTechnician($where);
        if($info){
            show200_admin($info['data'],$info['count']);
        }else{
            show400_admin();
        }
    }
    public function del()
    {
        $id = $this->input->post('commentId', TRUE);
        if(!$id) {
            show400('未获取到数据');
        }
        $info = $this->comment_model->del($id);
        if($info){
            show200('删除成功');
        }else{
            show400('删除失败');
        }
    }

    public function add()
    {
        $commentId = $this->input->get('commentId',TRUE);
        $info = $this->comment_model->getOne($commentId);
//        var_dump($info);
        self::$data['info']=$info;
        $this->load->view('seller/comment/add.html', self::$data);
    }

    public function repaly()
    {
        $this->load->view('seller/comment/repaly.html');
    }

    public function addrepaly()
    {
        $companyId=$this->checkCompany();
        $res = $this->comment_model->addrepaly($companyId);
        if ($res){
            show200('操作成功');
        }else{
            show400('操作失败');
        }

    }
}